<%@page import="com.kaishengit.entity.Sale"%>
<%@page import="com.kaishengit.util.Page"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.kaishengit.entity.User"%>
<%@page import="com.kaishengit.util.Stringutil"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
 
    
    <title>My JSP 'list.jsp' starting page</title>
   <link rel="stylesheet"  type="text/css"  href="style/bootstrap.min.css"/>
   <style  type="text/css">
   		input{
   			height:30px;
   		}
   </style>
	<script type="text/javascript" src="script/jquery.js"></script>
	<script type="text/javascript" src="script/bootstrap-modal.js"></script>
	<script type="text/javascript" src="script/bootstrap-dropdown.js"></script>
  </head>
  
  <body>
  
  <div style="z-index: 5" class="topbar-wrapper">
    <div data-dropdown="dropdown" class="topbar">
      <div class="topbar-inner">
        <div class="container">
          <h3><a href="#">Project Name</a></h3>
          <ul class="nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
            <li class="dropdown">
              <a class="dropdown-toggle" href="#">Dropdown</a>
              <ul class="dropdown-menu">
                <li><a href="#">Secondary link</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Another link</a></li>
              </ul>
            </li>
          </ul>
     
          <ul class="nav secondary-nav">
            <li class="dropdown">
              <a class="dropdown-toggle" href="#">Dropdown</a>
              <ul class="dropdown-menu">
                <li><a href="#">Secondary link</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Another link</a></li>
              </ul>
            </li>
            <li  style="fond-size:20px"><a>欢迎管理员：</a></li>
            <%User user = (User)session.getAttribute("admin"); %>
            <li ><a style="fond-size:20px"><%=user.getName() %></a></li>
          </ul>
        </div>
      </div><!-- /topbar-inner -->
    </div><!-- /topbar -->
  </div>
  <div  style="margin-top:80px">
  		<a class="showMode2" href="javascript:void(0)" ><input type="button" value="添加记录"  class="btn success"/></a>
	<div id="my-moda2" class="modal hide fade">	
	<div class="modal-header">
	  <a  href="" class="close">&times;</a>
	  <h3>添加销售记录</h3>
	</div>
	<form action="product.html?s=addprod"  method="post"  id="myformtian">
   			日期：<input type="text"  name="time"  /><br/><br/>
   			单位：<input type="text"  name="danwei"  /><br/><br/>
   			导游：<input type="text"  name="daoyou" onblur="senddaoyou()"  id="mydaoyou" /><br/><br/>
   			电话：<input type="text"  name="tel"  style="display: none"  id="mytel"/><br/><br/>
   			人数：<input type="text"  name="renshu"  /><br/><br/>
   			客源地：<input type="text" name="keyuan"  /><br/><br/>
   			销售额：<input type="text"  name="xiaoshoue" /><br/><br/>
   			<div class="modal-footer">
				<input type="submit"   value="添加"  class="btn success" id="mysubmittian"/>
				<a href="javascript:void(0)" class="btn secondary exit"  >取消此添加操作</a>
			</div>
   </form>
</div>
   
	
  		<a  class="showModel" href="javascript:void(0)" ><input type="button"  value="搜索纪录"  class="btn success"/></a>
  			<div id="my-modal" class="modal hide fade">
  				<div class="modal-header">
	 				 <a href="javascript:void(0)" class="close">&times;</a>
	 				 <h3>自定义搜索,请按照下列要求准确填写，不然可能会查询错误，不填写默认不按照此条件查询</h3>
				</div>
  					 <form  action="product.html?s=ss"  method="post">
   			
					   		单位名称：<input type="text"  name="danwei"/>英文或拼音或汉字<br/><br/>
					   		导游名：<input  type="text"  name="daoyou"/>英文或拼音或汉字<br/><br/>
					   		客源地：<input type="text"  name="keyuan"/>英文或拼音或汉字<br/><br/>
					   		销售时间  <input  type="text" name="mintime"/> 到<input type="text"  name="maxtime"/>2012-10-10<br/><br/>
					   		销售额        <input  type="text" name="minxiaoshoue"/> 到 <input  type="text" name="maxxiaoshoue"/>数字<br/>
					   			<div class="modal-footer">
					   		<input type="submit" value="搜索"  class="btn primary del"/>
					   		</div>
					   </form>
					   	<div class="modal-footer">
							 <a href="javascript:void(0)" class="btn secondary exit">取消此搜索操作</a>
						 </div>
  			</div>
  			
  			<a id="import" href="javascript:void(0)" rel="1"><input type="button"  value="导入excel"  class="btn success"/></a><br/>
		 <div id="importmodal" class="modal hide fade">
	<div class="modal-header">
	  <a href="#" class="close">&times;</a>
	  <h3>请选择文件</h3>
	</div>
	<div class="modal-body">
	 <form id="importfile" action="product.html?s=import" method="post" enctype = "multipart/form-data">
				<input id="fileInput" class="input-file" name = "file" type="file">
				</form>
	</div>
	<div class="modal-footer">
	 <span class="message">导入excel文件到数据库中</span>
			<button id="confirm" class="btn btn-primary">导入</button>
	</div>
  </div>
  		<table   class="bordered-table">
  		
  			<thead>
  				<tr><th>时间</th><th>单位</th><th>导游</th><th>客源地</th><th>人数</th><th>销售额</th><th>客单价</th><th>编辑</th><th>删除</th><tr>
  			</thead>
  			<tbody>
  				 <% Page<Sale> pagelist = (Page<Sale>) request.getAttribute("pagelist");
  					List<Sale>  salelist = pagelist.getResult();
  					 List<Sale> listall = (List<Sale>) request.getAttribute("listAll");
  					
  					if(salelist==null){%>
  						<tr>没有数据</tr>
  					<%}else {
  					int count = pagelist.getCount();
  					int renshu = 0;
  					 float totalsale = 0;
  					 float danjia = 0;
  					for(int j = 0;j<listall.size();j++){
  					totalsale+=listall.get(j).getSale();
  					renshu+=listall.get(j).getNum();
  					}
  					if(renshu==0){
  					danjia=0;
  					}else {
  					danjia = totalsale/renshu;
  					Stringutil su = new Stringutil();
  					danjia = su.getFloat(danjia);
  					}
  					
  					for(int i=0;i<salelist.size();i++){
  					Sale s = salelist.get(i);
  					
  						
  					%>
  					<tr>
  					
  					<td><%=s.getTime() %></td>
  					<td><%=s.getTour().getTourname() %></td>
  					<td><%=s.getGuide().getName() %></td>
  					<td><%=s.getAddress() %></td>
  					<td><%=s.getNum() %></td>
  					<td>￥<%=s.getSale() %></td>
  					<td>￥<%=s.getPersale() %></td>
  					<td><a class="showMode3"  	href="javascript:void(0)" ><input type="button" value="编辑记录"  class="btn success"/></a></td>
	<div id="my-moda3" class="modal hide fade">	
	<div class="modal-header">
	  <a  href="" class="close"  style="color:black;"><input type="button"  value="取消此编辑操作"  class="btn success"  style="color:black"/></a>
	  <h3>编辑销售记录</h3>
	</div>
	<form action="product.html?s=bianji" method="post">
   			
   			日期：<input type="text"  name="time"  value="<%=s.getTime() %>"/><br/><br/>
   			单位：<input type="text"  name="danwei"  value="<%=s.getTour().getTourname() %>"/><br/><br/>
   			导游：<input type="text"  name="daoyou"  value="<%=s.getGuide().getName()  %>"/><br/><br/>
   			人数：<input type="text"  name="renshu"  value="<%=s.getNum() %>"/><br/><br/>
   			客源地：<input type="text" name="keyuan"  value="<%=s.getAddress() %>"/><br/><br/>
   			销售额：<input type="text"  name="xiaoshoue"  value="<%=s.getSale() %>"/><br/><br/>
   			<input type="hidden"  name="id" value="<%= s.getId()%>"/>
   			<div class="modal-footer">
				<input type="submit"  value="编辑"  class="btn success" />

			</div>
   </form>
</div>
   
	
	
  
 
  					<td><a class="showModel1"  rel="<%=s.getId()%>"><button  class="btn danger">删除</button></a><br/></td>
  					</tr>
  					<div id="my-modal1" class="modal hide fade">
	<div class="modal-header">
	  <a href="#" class="close"  ><input type="button"  value="取消此删除操作"  class="btn success"  style="color:black;fond-size:20"/></a>
	  <h3>系统提示</h3>
	</div>
	<div class="modal-body">
	  <p style="color:red">你确定要删除此数据?</p>
	</div>
	<div class="modal-footer">
	  <a href="javascript:void(0)" class="btn primary del1">删除</a>
	 
	</div>
  </div>
	
  					<%} %>
  			</tbody>
  			<tfoot> 
  					<tr>
  						<td>总记录条数是：<%=count %></td>
  						<td>总销售额是：<%=totalsale %></td>
  						<td>总人数：<%=renshu %></td>
  						<td>平均客单价：<%=danjia %></td>
  					</tr>
  			</tfoot>
  			
  		</table>
  		
  		<div class="pagination">
  		<ul>
  				<%if(pagelist.getPageNum()==1){%>
  				<li class="prev disabled"><a>首页</a></li>	
  				<%}else {%>
  				<li class="prev"><a href="product.html?p=1&s=chaxun">首页</a></li>
  				<%}
  				if(pagelist.getPageNum()==1){%>
  				<li><a>上一页</a></li>
  				<%}else {%>
  				<li><a href="product.html?s=chaxun&p=<%=pagelist.getPageNum()-1%>">上一页</a></li>
  				<%} if(pagelist.getPageNum()==pagelist.getTotalPages()){%>
  				<li><a >下一页</a></li>
  				<%} else {%>
  				<li><a href="product.html?s=chaxun&p=<%=pagelist.getPageNum()+1%>">下一页</a></li>
  				<%} if(pagelist.getPageNum()==pagelist.getTotalPages()){%>
  				<li class="next disabled"><a>尾页 </a></li>
  				<%}  else {%>
  				<li class="next"><a href="product.html?s=chaxun&p=<%=pagelist.getTotalPages() %>">尾页 </a></li>
  				<%}%>
  				<li><a>总共<%=pagelist.getTotalPages() %>页</a></li>
  				
  		</ul>
  		<ul  class="pagination">
  		<li><a>直接去第</a></li><li><a><form  action="product.html?s=chaxun"  method="post"  style="height:20px">
  					<input  type="text"  name="p" style="width:30px"/>
  					<span>页</span>
  					<input type="submit"  value="go"/>
  				</form></a></li>
  		</ul>
  		</div>
  		<%} %>
  		</div>
  </body>
  <script  type="text/javascript">
  var xmlHttp;
  function createXmlHttp(){
  	if(window.ActiveXObject){
  		xmlHttp = new  ActiveXObject("Microsoft.XMLHTTP");
  	}else {
  		
  	}
  }
  
  				//搜索
		$(document).ready(function(){
			$("#my-modal").modal({
					backdrop:true
			});
			$(".showModel").click(function(){
				
				$("#my-modal").modal('show');
			});
			$(".exit,.close").click(function(){
				$('#my-modal').modal('hide');
			});
			//删除
			var id;
		
			$("#my-modal1").modal({
					backdrop:true
			});
			$(".showModel1").click(function(){
				id = $(this).attr("rel");
				$("#my-modal1").modal('show');
			});
		$(".exit,.close").click(function(){
				$('#my-modal1').modal('hide');
			});
			$(".del1").click(function(){
				window.location.href="product.html?s=toshanchu&id="+id;
			});
			//添加记录
			$("#my-moda2").modal({
					backdrop:true
			});
			$(".showMode2").click(function(){
				
				$("#my-moda2").modal('show');
			});
			$(".exit,.close").click(function(){
				$('#my-moda2').modal('hide');
			});
			
			
			//编辑
			$("#my-moda3").modal({
					backdrop:true
			});
			$(".showMode3").click(function(){
				
				$("#my-moda3").modal('show');
			});
			$("#quxiao,.close").click(function(){
				$('#my-moda3').modal('hide');
			});
			//下拉框
			$('#topbar').dropdown();
			//导入excel
				$("#import").click(function() {
				$("#importmodal").modal("show");
			});

			$("#confirm").click(
					function() {
						var reg = /.xls$/;
						if (reg.test($("#fileInput").val())) {
							$("#importmodal").modal("hide");
							$("#importfile").submit();
						} else {
							$(".message").text("不是标准的excel文件(.xls)").css(
									"color", "red");
						}
			});
			//添加电话
			var xmlHttp;
			function createXmlHttp(){
				if(window.ActiveXObject){
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}else {
					xmlHttp=new XMLHttpRequest();
				}
			}
			function  senddaoyou(){
				createXmlHttp();
				var namedaoyou= document.getElementById("mydaoyou").value;
				xmlHttp.open("post","product.html?s=addprod",true);
				xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlHttp.onreadystatechange=callback;
				xmlHttp.send("name="+namedaoyou);
			}
			function callback(){
				if(xmlHttp.readyState==4){
					if(xmlHttp.status==200){
						var re = xmlHttp.responseText;
						if(re=="kong"){
							document.getElementById("mytel").style.display="inline";
						}
					}	
				}
			}
		});
  </script>
</html>
